package daohibernate;

import hibernate.HibernateUtil;
import negocio.beans.oficinaventa.Cotizacion;
import negocio.beans.oficinaventa.Item;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class ItemDAO {
	private static ItemDAO instancia = null;
	private static SessionFactory sf = null;
	
	
	public static ItemDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ItemDAO();
		} 
		return instancia;
	}
	
	
	public void grabarItems(Cotizacion c){
		Session s = sf.openSession();
		s.beginTransaction();	
		
		for(Item it:c.getItems()){
			it.setCotizacion(c);
			s.persist(it);
		}		
		s.flush();
		s.getTransaction().commit();
	}

}
